<?php

/**
 * Admin Template Controller.
 *
 * @version  $Id: template.php 2 2009-10-02 23:06:43Z perfilev $
 * @package  Application
 */

abstract class Controller_Admin_Template extends Controller_Template
{
	/**
	 * @var  string  Page template.
	 */
	protected $template = 'admin/template';

	protected $resource = 'admin';

	/**
	 * Authenticates user.
	 *
	 * @return void
	 */
	public function before()
	{
        if ((isset($_SESSION['identity']['role'])&&($_SESSION['identity']['role'])=='member')){
            unset($_SESSION['identity']);
        }
		parent::before();
		$this->auth = Auth::getInstance();
		if (false == $this->auth->hasIdentity()) {
			$this->response->redirect('/auth/signin/');
		} else {
			if ($this->auth->allowed('admin', 'signin')) {
				View::$global['identity'] = $this->auth->getIdentity();
			} else {
                if ((isset($_SESSION['identity']['role'])&&($_SESSION['identity']['role'])=='member')){
                    unset($_SESSION['identity']);
                }
				throw new ForbiddenException('Access denied to the admin controller from member account. Please reload page!');
			}
		}

//		$this->addScript('/scripts/jquery/jquery.js');
//		$this->addScript('/scripts/jquery/jquery-ui.js');
//        $this->addScript('/scripts/jquery/12/jquery.js');
//        $this->addScript('/scripts/jquery/12/jquery-ui.min.js');
        $this->addScript('/scripts/jquery/1.7.2/jquery1.7.2.js');
        $this->addScript('/scripts/jquery/1.7.2/jquery-ui-1.8.21.custom.min.js');

		$this->addScript('/scripts/admin.js');
        $this->addScript('/scripts/eva.js');
        $this->addStyle('/styles/eva.css');
	}
}
